package com.itheima.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/demo02")
public class ResponseDemo02Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          //地址栏访问 通过get请求进行处理
        System.out.println("请求来了，我使用getWriter()对外输出");
       //因为字节流只能写字节 所以需要将字符串转换成字节数组
        response.setContentType("text/html;charset=utf-8");

        PrintWriter writer = response.getWriter();

        writer.write("你好");//write是以字符形式写的 100 转换成字符 d
        writer.print(100);// 它存在方法重载，有专门写int类型的方法

    }
}
